package com.grandbroad.eim.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.grandbroad.eim.R;
import com.grandbroad.eim.entry.ClassIconBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IconListAdapter extends RecyclerView.Adapter<IconListAdapter.MylsitViewholder> {


   private List<ClassIconBean> classIconBeanList = new ArrayList<>();

    public void setClassIconBeanList(List<ClassIconBean> classIconBeanList) {
        this.classIconBeanList = classIconBeanList;
    }

    @NonNull
    @Override
    public MylsitViewholder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.class_icon_item, viewGroup, false);
        return new MylsitViewholder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull MylsitViewholder mylsitViewholder, int i) {
        ClassIconBean bean = classIconBeanList.get(i);
        mylsitViewholder.imgIcon.setBackgroundResource(bean.getRes());
        mylsitViewholder.tvIconName.setText(bean.getTag());
    }

    @Override
    public int getItemCount() {
        return classIconBeanList.size();
    }

    class MylsitViewholder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.tv_icon_name)
        TextView tvIconName;
        @BindView(R.id.li_icon_item)
        LinearLayout liIconItem;
        public MylsitViewholder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
